package com.hare.harelearn.DataStructure.structure.栈存储结构.栈顺序存储结构;

import java.util.Stack;

/**
 * @program: HareLearn
 * @description:  栈顺序存储结构
 * @author: Hare
 * @create: 2025−05-22 17:09
 * @Version 1.0
 **/
public class StackSort {
    static Integer [] stack =new Integer[6];
    // 栈顶top
    static int top = -1;
    // 栈底bottom
    static int bottom = 0;

    static {
        stack[0]=1;
        stack[1]=2;
        stack[2]=3;
        stack[3]=4;
        stack[4]=5;

        // 栈底栈顶赋值
        top = stack.length-2;
        bottom = 0;
    }

    public static void main(String[] args) throws Exception {
        Stack stack = new Stack();

        //System.out.println(pop());  // 出栈

        push(6);
    }

    /**
     * 出栈
     */
    public static Integer pop() throws Exception {
        if(!stackEmpty()){
            throw new Exception("栈为空~~~");
        }
        Integer[] stackNum = StackSort.stack;
        Integer result = stackNum[StackSort.top];
        top--;
        return result;
    }

    /**
     * 进栈
     */
    public static void push(int num) throws Exception {
        if(stackFull()){
            throw new Exception("栈满了~~~");
        }
        top++;
        stack[top] = num;
    }

    /**
     * 判断栈是否为空
     * 是否为空即判断top==-1即可
     */
    public static boolean stackEmpty() {
        if(StackSort.top == -1){
            return false;
        }
        return true;
    }

    /**
     * 判断栈是否已满
     */
    public static boolean stackFull() {
        if(StackSort.top == StackSort.stack.length-1){
            return true;
        }
        return false;
    }
}
